import fetch from 'common/src/utils/fetch';
import UTILS from "common/src/utils/utils";

// let apiPrefix = '/dev';
let apiPrefix = '/api/studentservice/';
function dealQeury(params) {
  let query = '?';
  for (let key in params) {
    query += key;
    query += '=';
    query += params[key];
    query += '&';
  }
  return query.substring(0, query.length - 1)
}
/**
 * 查询
 * @param data
 */
export function queryAssessTime(id, deptId) {
  return fetch({
    url: apiPrefix + 'assessApply/queryAssessTime?studentId='+id+'&deptId='+deptId,
    method: 'get'
  })
}

/**
 * 根据学生ID查询选题申请信息
 * @param data
 */
export function queryAssessStudent(params) {
  return fetch({
    url: `${apiPrefix}assessApply/queryAssessStudent${dealQeury(params)}`,
    method: 'get'
  })
}

/**
 * 根据学生ID查询选题申请信息
 * @param data
 */
export function queryPaperStudent(id) {
  return fetch({
    url: `${apiPrefix}assessApply/queryPaperStudent?studentId=${id}`,
    method: 'get'
  })
}

/**
 * 新增选题规则保存
 * @param data
 */

export function saveCachedAssess(data) {
  return fetch({
    url: `${apiPrefix}assessApply/saveCachedAssess`,
    method: 'post',
    data
  })
}

/**
 * 根据学生ID查询选题申请信息
 * @param data
 */
export function queryAllAssessInfo(data) {
  return fetch({
    url: `${apiPrefix}assessApply/queryAllAssessInfo`,
    method: 'post',
    data
  })
}

/**
 * 查询章节模板信息
 * @param data
 */
export function queryChapterInfo(params) {
  return fetch({
    url: `${apiPrefix}assessApply/queryChapterInfo${dealQeury(params)}`,
    method: 'get',
  })
}

/**
 * 查询章节信息
 * @param data
 */
export function queryDetailByPaperId(id) {
  return fetch({
    url: `${apiPrefix}assessApply/queryDetailByPaperId?paperId=${id}`,
    method: 'get',
  })
}
/**
 * 提交章节信息
 * @param data
 */
export function saveNormalAssess(data) {
  return fetch({
    url: `${apiPrefix}assessApply/saveNormalAssess`,
    method: 'post',
    data
  })
}

/**
 * 选题基本规则
 * @param data
 */
export function queryAllPaperById(id) {
  return fetch({
    url: `${apiPrefix}assessApply/queryAllPaperById?paperId=${id}`,
    method: 'get',
  })
}

/**
 * @param data
 * 考核数据导出接口：
 */
export function exportAssessInfoList(data) {
  return fetch({
    url: `${apiPrefix}assessApply/exportAssessInfoList`,
    method: 'post',
    responseType: 'blob',
    data
  })
}
/**
 * @param data
 * 中期考核工作申请导出/69
 */
export function exportAssessInfoWord(id) {
  return `${apiPrefix}assessApply/exportAssessInfoWord?applyId=${id}&exportType=2`
}
/**
 * @param data
 * 中期考核工作申请导出/69
 */
export function exportAssessInfoPdf(id) {
  return `${apiPrefix}assessApply/exportAssessInfoPdf?applyId=${id}&exportType=2`
}
/**
 * 中期考核方案二导出
 * @param {*} id 
 */
export function exportAssessInfoPdf2(id) {
  return `${apiPrefix}assessApply/exportAssessInfoPdf2?applyId=${id}&exportType=2`
}
/**
 * 预览个人小结pdf部分
 * @param {*} id 
 */
export function previewPersonTitle(id,studentId) {
  return `${apiPrefix}assessApply/previewPersonTitle?applyId=${id}&exportType=2&studentId=${studentId}`
}

/**
 * 选题结果查询
 * @param data
 */
export function findResultQuery(data) {
  return fetch({
    url: `${apiPrefix}assessApply/findResultQuery`,
    method: 'post',
    data
  })
}

/**
 * 选题结果查询导出
 * @param data
 */
export function exportResultQuery(data) {
  return fetch({
    url: `${apiPrefix}assessApply/exportResultQuery`,
    method: 'post',
    data: data,
    responseType: 'blob'
  }).then(res => {
    UTILS.downloadFile(res, 'AssessResultQueryList.xls', 'application/vnd.ms-excel;charset=utf-8');
  });
}

/**
 * 选题结果汇总导出
 * @param data
 */
export function exportResultSum(data) {
  return fetch({
    url: `${apiPrefix}assessApply/exportResultSum`,
    method: 'post',
    data: data,
  }).then(res => {
    UTILS.downloadFile(res, 'AssessResultSum.xls', 'application/vnd.ms-excel;charset=utf-8');
  });
}

export function recallAssess(id) {//撤回
  return fetch({
    url: `${apiPrefix}/assessApply/recallAssess?applyId=${id}`,
    method: 'post'
  })
}
export function queryIsApply(id) {//论文工作申请页面查询数据是否可编辑
  return fetch({
    url: `${apiPrefix}assessApply/queryIsApply?studentId=${id}`,
    method: 'get'
  })
}

// 撤回审批
//http://127.0.0.1:8110/assessApply/batchReverseAudit
export function batchReverseAudit(data) {
  return fetch({
    url: `${apiPrefix}assessApply/batchReverseAudit`,
    method: 'post',
    data
  })
}

//论文选题最终版本上传
export function addFinalVersion(data) {
  return fetch({
    url: `${apiPrefix}aversion/addFinalVersion`,
    method: 'post',
    data
  })
}

//论文选题最终版本查询
export function queryFinalVersion(data) {
  return fetch({
    url: `${apiPrefix}aversion/page`,
    method: 'post',
    data
  })
}

//论文选题最终版本导出
export function exportFinalVersionList(data) {
  return fetch({
    url: `${apiPrefix}aversion/exportFinalVersionList`,
    method: 'post',
    responseType: 'blob',
    data
  }).then(res => {
    UTILS.downloadFile(res, 'AssessFinalVersionList.xlsx', 'application/vnd.ms-excel;charset=utf-8');
  });
}

//查询该学生最终版本信息
export function getFinalVersionInfo() {
  return fetch({
    url: `${apiPrefix}aversion/info/finalVersion`,
    method: 'post'
  })
}

export default {
  findResultQuery,
  queryAssessTime,
  queryAssessStudent,
  queryPaperStudent,
  saveCachedAssess,
  queryAllAssessInfo,
  queryChapterInfo,
  queryDetailByPaperId,
  saveNormalAssess,
  queryAllPaperById,
  exportAssessInfoList,
  exportAssessInfoWord,
  exportAssessInfoPdf,
  exportAssessInfoPdf2,
  previewPersonTitle,
  exportResultQuery,
  exportResultSum,
  recallAssess,
  queryIsApply, batchReverseAudit
}
